def exist(self, board, word):
    temp = []
    result = []
    def trackback(heng, shu, index, judge):
        if result != []:
            return
        if heng >= len(word) or heng < 0 or shu >= len(word) or shu < 0:
            return
        if len(temp) == len(word):
            result.append(1)
            return
        for i in range(0, len(board)):
            for j in range(0, len(board)):
                if board[heng][shu] == word[index] and judge[heng][shu] == 0:
                    temp.append(word[index])
                    judge[heng][shu] = 1
                    trackback(shu - 1, heng, index + 1, judge)
                    trackback(shu + 1, heng, index + 1, judge)
                    trackback(shu, heng - 1, index + 1, judge)
                    trackback(shu, heng + 1, index + 1, judge)
                    temp.pop()
                    judge[heng][shu] = 0

    judge = [[0] * (len(board) - 1) for _ in range(len(board))]
    trackback(0, 0, 0, judge)
    return result != []


if __name__ == "__main__":
    exist()